import { FileItemModel } from "@/api/interface/index";
import http from "@/api";

export interface CategoryGetReturnItemModel {
	id: number;
	parentId?: number;
	icon?: FileItemModel[];
	name: string;
	type: string;
	createTime?: number;
	updateTime?: number;
	children?: CategoryGetReturnItemModel[];
}
/**
 * 获取商品一级分类
 */
export function categoryGetOne() {
	return http.get<CategoryGetReturnItemModel[]>("/category/getOne", undefined, { headers: { noLoading: true } });
}

/**
 * 根据一级id获取二级分类（不传为查询全部）
 */
export function categoryGetTwo(params: { parentId?: number } = {}) {
	return http.get<CategoryGetReturnItemModel[]>("/category/getTwo", params, { headers: { noLoading: true } });
}

interface categoryModifySendModel {
	className: string; // 传one || two （一级或二级）
	name: string; // 名称
	type: string; // 类型描述
	id?: string | number;
	icon?: string | number;
	parentId?: string | number;
}
/**
 * 新增或修改一级（二级）分类
 */
export function categoryModify(data: categoryModifySendModel) {
	return http.post("/category/modify", data, { headers: { noLoading: true } });
}
interface CategoryDeleteSendModel {
	id: number;
	className: string; // 传one || two （一级或二级）
}
/**
 * 删除一级或二级分类
 */
export function categoryDelete(params: CategoryDeleteSendModel) {
	return http.delete("/category/delete", params, { headers: { noLoading: true } });
}
